package org.todo.controller;

import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.springframework.web.portlet.mvc.AbstractController;
import org.springframework.web.portlet.ModelAndView;

import org.springframework.web.portlet.bind.PortletRequestUtils;
import org.todo.domain.Todo;
import org.todo.service.TodoService;

/**
 * Controller that handles the rendering of the details of a todo item
 * @author Matthias Braunhofer
 */
public class TodoDetailController extends AbstractController {
    //injected dependency
    private TodoService todoService;

    /**
     * Handler method that handles the rendering of todo detail requests
     * @param request
     * @param response
     * @return
     * @throws java.lang.Exception
     */
    @Override
    protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {
        int todoId = PortletRequestUtils.getIntParameter(request, "todoId");

        Todo todo = todoService.getTodo(todoId);
        
        return new ModelAndView("todoDetail", "todo", todo);
      }
  
    public void setTodoService(TodoService todoService) {
        this.todoService = todoService;
    }
}
